import { usePageRequest } from "../../../../utils/request";
import dayjs from "../../../../utils/day";

Component({
    properties: {},
    data: {},
    methods: {
        onLoad() {
            this.request = new usePageRequest('api/systemmsg', {
                pretreatment: data => {
                    data.list = data.list.map(item => {
                        item.date = dayjs.unix(item.release_time).format('YYYY年M月D日 HH:mm:ss')
                        const textContent = item.content ? item.content.filter(item => item.type == 1) : []
                        if (textContent.length) {
                            item.contentText = textContent[0].content
                        } else {
                            item.contentText = ''
                        }
                        return item
                    })
                    return data
                }
            }, this)
        },
        detail(e) {
            const data = this.data.data[e.currentTarget.dataset.index]
            wx.navigateTo({
                url: '/pages/message/notice/detail/detail',
                success: result => {
                    result.eventChannel.emit('getDetail', data)
                }
            })
        }
    }
});
